package com.endbd.purchase.manage.type.control;


import com.endbd.feignapi.model.purchase.CType;
import com.endbd.feignapi.util.PageModel;
import com.endbd.feignapi.util.ResultMessage;
import com.endbd.purchase.manage.type.model.TypeCondition;
import com.endbd.purchase.manage.type.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/purchase")
@RestController
public class TypeAction {
    @Autowired
    private ITypeService typeService;


    @RequestMapping("/typeName")
    public ResultMessage TypeName(TypeCondition tcon){
        List<String> typeName = typeService.querytypeName(tcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("查询成功！");
        msg.setResultData(typeName);
        return msg;
    }

    @RequestMapping("/typePage")
    public ResultMessage TypePage(PageModel<CType> pageModel , TypeCondition tcon){
        PageModel<CType> typePageModel = typeService.queryTypePageByCondition(pageModel,tcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("查询成功！");
        msg.setResultData(typePageModel);
        return msg;
    }

    @RequestMapping("/addType")
    public ResultMessage AddType(CType type,String brandName){
        typeService.addType(type,brandName);

        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("添加了"+type.getTypeName()+"商品类型");
        return msg;
    }

    @RequestMapping("/alterType")
    public ResultMessage alterType(CType type,String brandName){
        typeService.alterType(type,brandName);

        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("修改为"+type.getTypeName()+"商品类型");
        return msg;
    }

    @RequestMapping("/lorType")
    private ResultMessage lorType(TypeCondition tcon){
        typeService.lorType(tcon);

        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        if (tcon.getTypeStatus()==1){
            msg.setMsg("禁用了"+tcon.getTypeName()+"商品类型");
        }else {
            msg.setMsg("恢复了"+tcon.getTypeName()+"商品类型");
        }
        return msg;
    }

}
